'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/pages/kh/dsjzxgl/dsj/batchup 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			lists
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		//接收前端传过来的参数
		let {

			huichuan
		} = data

		let batchRunRes = await vk.pubfn.batchRun({
			// 主执行函数
			main: async (item, index) => {
				await vk.pubfn.sleep((Math.floor(Math.random() * (3 - 0)) + 0) * 100);
				const batchdown = await db.collection('a_config').where({
					tfid: item._id,
					name: "RebackPercent",
				}).update({
					douyinRadio: huichuan.douyinRadio,
					kuaishouRadio: huichuan.kuaishouRadio,
					tengxunRadio: huichuan.tengxunRadio,
					ucRadio: huichuan.ucRadio,
					baiduRadio: huichuan.baiduRadio,
					oppoRadio: huichuan.oppoRadio,
					douyin_ReturnRatio: huichuan.douyin_ReturnRatio,
					douyin_UnReturnRatio: huichuan.douyin_UnReturnRatio,
					kuaishou_ReturnRatio: huichuan.kuaishou_ReturnRatio,
					kuaishou_UnReturnRatio: huichuan.kuaishou_UnReturnRatio,
					tengxun_ReturnRatio: huichuan.tengxun_ReturnRatio,
					tengxun_UnReturnRatio: huichuan.tengxun_UnReturnRatio,
					uc_ReturnRatio: huichuan.uc_ReturnRatio,
					uc_UnReturnRatio: huichuan.uc_UnReturnRatio,
					baidu_ReturnRatio: huichuan.baidu_ReturnRatio,
					baidu_UnReturnRatio: huichuan.baidu_UnReturnRatio,
					oppo_ReturnRatio: huichuan.oppo_ReturnRatio,
					oppo_UnReturnRatio: huichuan.oppo_UnReturnRatio,
					newuser: huichuan.newuser,
					firstorder: huichuan.firstorder,
					douyin: huichuan.douyin * 1,
					douyin_url: huichuan.douyin_url,
					douyin_token: huichuan.douyin_token,
					kuaishou: huichuan.kuaishou * 1,
					baidu: huichuan.baidu * 1,
					tengxun: huichuan.tengxun * 1,
					uc: huichuan.uc * 1,
					baidu_token: huichuan.baidu_token,
					oppo: huichuan.oppo * 1,
					oppo_owner_id: huichuan.oppo_owner_id,
					oppo_api_id: huichuan.oppo_api_id,
					oppo_api_key: huichuan.oppo_api_key,
					douyinMinPrice: huichuan.douyinMinPrice,
					douyinMaxPrice: huichuan.douyinMaxPrice,
					kuaishouMinPrice: huichuan.kuaishouMinPrice,
					kuaishouMaxPrice: huichuan.kuaishouMaxPrice,
					baiduMinPrice: huichuan.baiduMinPrice,
					baiduMaxPrice: huichuan.baiduMaxPrice,
					ucMinPrice: huichuan.ucMinPrice,
					tengxunMinPrice: huichuan.tengxunMinPrice,
					tengxunMaxPrice: huichuan.tengxunMaxPrice,
					oppoMinPrice: huichuan.oppoMinPrice,
					oppoMaxPrice: huichuan.oppoMaxPrice,
					hour_backhaul: huichuan.hour_backhaul * 1,
				})
				return {
					code: 0,
					index
				}
			},
			// 最大并发量，如果设置为1，则会按顺序执行
			concurrency: 100,
			// 数据源，这些数据会依次跑一遍main函数
			data: lists
		});



		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}